package com.bub.pay.framework.common.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.PostConstruct;

/**
 * swagger
 * 只在dev环境启用
 *
 * @author recall
 * @date 2019/7/18
 */
@Slf4j
@Configuration
@EnableSwagger2
@Profile("dev")
public class ConditionSwaggerConfig {

    private static volatile Boolean ENABLE = false;

    @PostConstruct
    public void init() {
        log.info("==================init====================");
        ENABLE = true;
    }

    public static void activeProfiles(String[] activeProfiles) {
        log.info("==================activeProfiles====================");
        if (activeProfiles == null) {
            return;
        }
        if (ArrayUtils.contains(activeProfiles, "dev")) {
            ENABLE = true;
        }
    }

    /**
     * 是否启用
     *
     * @return 是否启用
     */
    public static boolean isEnable() {
        log.info("==================isEnable[{}]====================", ENABLE);
        return ENABLE;
    }

}
